<?php
/**
 * Created by PhpStorm .
 * User: 杜磊磊
 * Date: 2020/7/3
 * Time: 15:11
 */
namespace app\api\controller;

use app\BaseController;
use app\common\business\User as UserBis;
use think\Request;

class User extends BaseController
{
    public function index(Request $request)
    {
        $user = (new UserBis())->getNormalUserById($request->userId);
        $result = [
            'username' => $user['username'],
            'phone_number' => $user['phone_number'],
            'sex' => $user['sex'],
        ];
        return show(config("status.success"),"OK",$result);
    }

    public function update(Request $request)
    {
        $username = $this->request->param("username","","trim");
        $sex = $this->request->param("sex","","intval");
        $data = [
            "username" => $username,
            "sex" => $sex,
        ];
        $validate = (new \app\api\validate\User())->scene("update_user");
        if (!$validate->check($data)){
            return show(config("status.error"),$validate->getError());
        }
        $userBisObj = new UserBis();
        $user = $userBisObj->update($request->userId,$data);
        if(!$user){
            return show(config("status.error"),"更新失败");
        }
        return show(config("status.success"),"Ok");
    }
}